package com.example.demo.service.imp;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.demo.dto.ActiveUserDto;
import com.example.demo.dto.FavorableDto;
import com.example.demo.dto.TurnoverDto;
import com.example.demo.mapper.DataStatisticsMapper;
import com.example.demo.mapper.TestMapper;
import com.example.demo.service.DataStatisticsService;
import com.example.demo.service.TestService;

@Service
@Transactional
public class DataStatisticsServiceImp implements DataStatisticsService{
	@Resource
	private DataStatisticsMapper DataStatisticsMapper;

	@Override
	public BigDecimal getTurnover() {
		return DataStatisticsMapper.getAllTurnover();	
	}

	@Override
	public int getUserNumber() {
		return DataStatisticsMapper.getAllUserNum();
	}
	
	@Override
	public int getCinema() {
		return DataStatisticsMapper.getAllCinema();
	}
	
	@Override
	public double getFavorableRate() {
		double allAppraise=(double)DataStatisticsMapper.getAllAppraise();
		int goodAppraise=DataStatisticsMapper.getAllGoodAppraise();
		//计算好评率
		double favorableRate=(goodAppraise/allAppraise)*100;
		return favorableRate;
	}

	@Override
	public List<FavorableDto> getFavorable() {
		List<FavorableDto> list=new ArrayList<>();
		FavorableDto f=new FavorableDto();
		//查询观看动作类电影人数
		int amovie=DataStatisticsMapper.getAmovie();
		f.setValue(amovie);
		f.setName("动作片");
		list.add(f);
		//查询观看悬疑类电影人数
		int dmovie=DataStatisticsMapper.getDmovie();
		f=new FavorableDto();
		f.setValue(dmovie);
		f.setName("悬疑片");
		list.add(f);
		//查询观看剧情类电影人数
		int fmovie=DataStatisticsMapper.getFmovie();
		f=new FavorableDto();
		f.setValue(fmovie);
		f.setName("剧情片");
		list.add(f);
		//查询观看喜剧类电影人数
		int cmovie=DataStatisticsMapper.getCmovie();
		f=new FavorableDto();
		f.setValue(cmovie);
		f.setName("喜剧片");
		list.add(f);
		//查询观看爱情类电影人数
		int rmovie=DataStatisticsMapper.getRmovie();
		f=new FavorableDto();
		f.setValue(rmovie);
		f.setName("爱情片");
		list.add(f);
		//查询观看奇幻类电影人数
		int smovie=DataStatisticsMapper.getSmovie();
		f=new FavorableDto();
		f.setValue(smovie);
		f.setName("奇幻片");
		list.add(f);
		return list;
	}

	@Override
	public List<TurnoverDto> getTurnoverTable(String odata) {
		//查询该年营业额
		List<TurnoverDto> list=DataStatisticsMapper.getTurnoverByYear(odata);
		return list;
	}

	@Override
	public List<ActiveUserDto> getActiveUserTable(String odata) {
		//查询活跃用户
		List<ActiveUserDto> list=DataStatisticsMapper.getActiveUser("2019"); 
		return list;
	}


}
